Skip to content

Conversation

JarmouniA
Copy link
Contributor

@JarmouniA JarmouniA commented Oct 12, 2025

In MCUBoot RAM LOAD mode, the app slot addr is taken as the hex-addr passed to imgtool to create slot0 & 1 images, which is only correct if the grand-parent node's (usually the flash node) absolute address is actually 0, because the addresses of all the flash fixed-partitions in-tree are relative to their grand-parent node's address.

Hence, use the newly added dt_fixed_partition_addr() CMake function to get the absolute address of app slots partitions.
dt_fixed_partition_addr() is equivalent to the MACRO

#define DT_FIXED_PARTITION_ADDR(node_id) \

@nordicjm
Copy link
Contributor

My first point would be that you are missing a ranges property for your flash controller, but I have just investigated by building for stm32n6570_dk and I'm a bit confused because that board does not even use RAM load?

@nordicjm
Copy link
Contributor

Saw you need to manually specify it, so it is not default. Anyhow, this fixes it with the ranges property, otherwise you are declaring that the flash partitions start at 0x0 in dts, which is wrong:

diff --git a/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi b/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
index 5b91c96d7d4..758b007f0c6 100644
--- a/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
+++ b/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
@@ -380,6 +380,8 @@ zephyr_udc0: &usbotg_hs1 {
 
 	mx66uw1g45g: ospi-nor-flash@0 {
 		compatible = "st,stm32-xspi-nor";
+		#address-cells = <1>;
+		#size-cells = <1>;
 		reg = <0>;
 		size = <DT_SIZE_M(1024)>; /* 1Gbits */
 		ospi-max-frequency = <DT_FREQ_M(200)>;
@@ -387,11 +389,13 @@ zephyr_udc0: &usbotg_hs1 {
 		data-rate = <XSPI_DTR_TRANSFER>;
 		four-byte-opcodes;
 		status = "okay";
+		ranges = <0x0 0x70000000 0x1000000>;
 
 		partitions {
 			compatible = "fixed-partitions";
 			#address-cells = <1>;
 			#size-cells = <1>;
+			ranges;
 
 			/*
 			 * Following flash partition is dedicated to the use of bootloader

@erwango
Copy link
Member

erwango commented Oct 14, 2025

My first point would be that you are missing a ranges property for your flash controller, but I have just investigated by building for stm32n6570_dk and I'm a bit confused because that board does not even use RAM load?

@nordicjm STM32N6 is a specific kind of STM32: there is no internal flash. In default mode, the BootROM (internal and non updatable bootloader) will load the binary (called First Stage Boot Loader) from ext flash (at a specific location) to RAM, which will then execute in XIP=n. FSBL can be a usual zephyr application or MCUBoot which will could then do it's usual job with application that would be also stored on ext flash.

endif()
set(imgtool_args_alt_slot ${imgtool_args} --hex-addr ${slot1_partition_address})
set(imgtool_args ${imgtool_args} --hex-addr ${slot0_partition_address})
math(EXPR SLOT0_PARTITION_ADDRESS "${CONFIG_FLASH_BASE_ADDRESS} + ${slot0_partition_address}")
Copy link
Contributor Author

@JarmouniA JarmouniA Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm implementing a CMake function in cmake.extensions, to replace dt_reg_addr above, that will give the absolute address of the slot partition, similar to the macro

#define DT_FIXED_PARTITION_ADDR(node_id) \

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good thing but nack on the board impact part for now

@JarmouniA JarmouniA force-pushed the fix_mcuboot_ramload_img_hexaddr branch 2 times, most recently from cf50563 to c6ca4e9 Compare October 18, 2025 11:30
Introduce a new dt_fixed_partition_addr() function that returns the
absolute address of a fixed partition, meaning the sum of the base
address of the containing grand-parent node and the partition's offset.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
In RAM LOAD mode, the app slot addr is taken as the hex-addr passed to
imgtool, which is only correct if the grand-parent node's (usually the
flash node) absolute address is actually 0, because the addresses of all
the flash fixed-partitions in-tree are relative to their grand-parent
node's address.

Hence, use the newly added dt_fixed_partition_addr() function to get the
absolute address of app slots partitions.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
@JarmouniA JarmouniA force-pushed the fix_mcuboot_ramload_img_hexaddr branch from c6ca4e9 to b8d5d47 Compare October 19, 2025 12:11
Copy link

@JarmouniA JarmouniA requested a review from erwango October 20, 2025 07:24
@JarmouniA
Copy link
Contributor Author

Probably a good thing but nack on the board impact part for now

Removed N6 modifs.

dt_fixed_partition_addr(slot0_partition_address PATH ${slot0_partition})
dt_nodelabel(slot1_partition NODELABEL "slot1_partition" REQUIRED)
dt_reg_addr(slot1_partition_address PATH ${slot1_partition})
dt_fixed_partition_addr(slot1_partition_address PATH ${slot1_partition})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I present a complete failure showcase for this:

diff --git a/dts/vendor/nordic/nrf52840_partition.dtsi b/dts/vendor/nordic/nrf52840_partition.dtsi
index 1fa90a3ed71..fd51c151379 100644
--- a/dts/vendor/nordic/nrf52840_partition.dtsi
+++ b/dts/vendor/nordic/nrf52840_partition.dtsi
@@ -23,15 +23,24 @@
 			reg = <0x00000000 0x0000C000>;
 		};
 
-		slot0_partition: partition@c000 {
+                slot_partitions: partition@c000 {
+                        compatible = "fixed-subpartitions";
+                        label = "image-0";
+                        reg = <0x0000c000 0xec000>;
+                        ranges = <0x0 0xc000 0xec000>;
+                        #address-cells = <1>;
+                        #size-cells = <1>;
+
+		slot0_partition: partition@0 {
 			label = "image-0";
-			reg = <0x0000C000 0x00076000>;
+			reg = <0x00000000 0x00076000>;
 		};
 
-		slot1_partition: partition@82000 {
+		slot1_partition: partition@76000 {
 			label = "image-1";
-			reg = <0x00082000 0x00076000>;
+			reg = <0x00076000 0x00076000>;
 		};
+};
 
 		/*
 		 * The flash starting at 0x000f8000 and ending at

Build samples/subsys/mgmt/mcumgr/smp_svr for nrf52840dk/nrf52840 with -DFILE_SUFFIX="ram_load" and observe the huge error. The issue on your board has the correct solution described on #97413 (comment) you are not setting ranges and then declaring a child node has address 0, this means it starts at physical address 0x0, your DTS file is wrong

Copy link
Contributor Author

@JarmouniA JarmouniA Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+      ranges = <0x0 0x70000000 0x1000000>;
 
 	partitions { 

Ranges here has no effect on the individual partitions absolute address (seen in devicetree_generated.h), because I think the immediate childnode is partitions, not the the partition@x itself. Adding ranges = <.... inside partitions node gives build errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need both ranges, the one with addresses on the outside one and one without parameters on the partitions node

Copy link
Contributor Author

@JarmouniA JarmouniA Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if ranges takes care of this, why do DT_FIXED_PARTITION_ADDR and DT_FIXED_SUBPARTITION_ADDR macros exist!?

@JarmouniA JarmouniA closed this Oct 20, 2025
@JarmouniA JarmouniA deleted the fix_mcuboot_ramload_img_hexaddr branch October 20, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants